//
//  MessafePushViewController.m
//  Runone
//
//  Created by runone01 on 16/9/6.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "MessafePushViewController.h"
#import "PromptTableViewCell.h"
#import "AppLocalManager.h"
#import "Define.h"
#import "RequestHelper.h"
#import "MJExtension.h"
#import "SysPersonalSettingInfoModel.h"
#import "PushModel.h"

@interface MessafePushViewController ()
@property(nonatomic,strong)NSArray *dataSource;
@property(nonatomic,strong)NSString *state;
@property(nonatomic,strong)SysPersonalSettingInfoModel *UserBasemodel;
@property(nonatomic,strong)PushModel *PushModel;
@property(nonatomic,strong)NSMutableArray *pushArray;
@property(nonatomic,strong)NSMutableArray *UIDArray;
@end

@implementation MessafePushViewController

#pragma  -------消息推送

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"推 送";
    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
    label.text=@"推 送";
    label.textAlignment=NSTextAlignmentCenter;
    label.textColor=[UIColor whiteColor];
    self.navigationItem.titleView=label;
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.tableView registerNib:[UINib nibWithNibName:@"PromptTableViewCell" bundle:nil] forCellReuseIdentifier:@"CellID"];
    _dataSource=@[@"路政车辆",@"行政车辆",@"交通事故",@"施工事件",@"两客一危",@"养护车辆",@"救援车辆"];
    _pushArray=[[NSMutableArray alloc] init];
    _UIDArray=[[NSMutableArray alloc] init];
    [self requestUserBase];
}

#pragma mark ---旧版个人设置接口-----
-(void)requestUserBase
{

    RequestHelper *requestHelper=[[RequestHelper alloc] init];
    RequestGinsengModel *getCurrentEventModel=[[RequestGinsengModel alloc] init];
    getCurrentEventModel.URL=GetCurrentDutyPersonalName;
    getCurrentEventModel.DataValue = @"";
    getCurrentEventModel.UpdatedTime=@"";
    getCurrentEventModel.SystemCode=@"GuangleHighway";
    getCurrentEventModel.MethodName=@"GetSysPersonalSettingInfo";
    requestHelper.block=^(RequestOutginseng *requestOutginseng,id dataValueModel){

        NSDictionary *dic=[requestOutginseng.DataValue mj_JSONObject];
        _UserBasemodel=[SysPersonalSettingInfoModel mj_objectWithKeyValues:dic];
        [_UIDArray addObject:_UserBasemodel];
        NSMutableDictionary *dicc = [_UserBasemodel.AlarmContent mj_keyValues];
        PushModel *TempModel = [PushModel mj_objectWithKeyValues:dicc];
        [_pushArray addObject:TempModel];
        [self.tableView reloadData];
    };

    [requestHelper RequestGinsengModel:getCurrentEventModel andPushController:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PromptTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellID" forIndexPath:indexPath];
    cell.carTypeLab.text=_dataSource[indexPath.row];
    if (_pushArray.count>0) {
        PushModel *model=_pushArray[0];
        SysPersonalSettingInfoModel *pushModel=_UIDArray[0];
        cell.model=model;
        cell.PushModel=pushModel;
        switch (indexPath.row) {
            case 0:
                if (model.highwaysVehicleAlarm == 1) {
                    cell.switchBtn.on=YES;
                }
                else
                {
                    cell.switchBtn.on=NO;
                }
                break;
            case 1:
                if (model.administrativeVehicleAlarm == 1) {
                    cell.switchBtn.on=YES;
                }
                else
                {
                    cell.switchBtn.on=NO;
                }
                break;
            case 2:
                if (model.trafficAccidentAlarm == 1) {
                    cell.switchBtn.on=YES;
                }
                else
                {
                    cell.switchBtn.on=NO;
                }
                break;
            case 3:
                if (model.constructionEventAlarm == 1) {
                    cell.switchBtn.on=YES;
                }
                else
                {
                    cell.switchBtn.on=NO;
                }
                break;
            case 4:
                if (model.busDangerousAlarm == 1) {
                    cell.switchBtn.on=YES;
                }
                else
                {
                    cell.switchBtn.on=NO;
                }
                break;
            case 5:
                if (model.curingVehicleAlarm == 1) {
                    cell.switchBtn.on=YES;
                }
                else
                {
                    cell.switchBtn.on=NO;
                }
                break;
            case 6:
                if (model.rescueVehicleAlarm == 1) {
                    cell.switchBtn.on=YES;
                }
                else
                {
                    cell.switchBtn.on=NO;
                }
                break;
            default:
                break;
        }

    }

    cell.switchBtn.tag=indexPath.row;
    
    if (self.clickBlock!=nil) {
        self.clickBlock(indexPath.row);
    }

    return cell;    

}

@end
